//
//  batter.m
//  baseball
//
//  Created by Donggi Hahm on 10. 04. 03.
//  Copyright 2010 ComTalk. All rights reserved.
//

#import "batter.h"
#import	"global.h"


@implementation batter

@synthesize spBatterReady, aniBatterReady, spBatterSwing, aniBatterSwing;

- (id) init
{
	if( (self=[super init]) ) 
	{
		m_windowSize = [[CCDirector sharedDirector] winSize];
		
		if ( m_windowSize.width == 768 )
			m_DeviceKind = DEVICE_IPAD;
		else
			m_DeviceKind = DEVICE_IPHONE;
		
		//
		// batter ready
		//
		CCTexture2D *textureReady = [[CCTextureCache sharedTextureCache] addImage:@"bat_ready.png"];
		
		// manually add frames to the frame cache
		CCSpriteFrame *frameReady0 = [CCSpriteFrame frameWithTexture:textureReady rect:CGRectMake(0, 0, 60, 160) offset:CGPointZero];
		CCSpriteFrame *frameReady1 = [CCSpriteFrame frameWithTexture:textureReady rect:CGRectMake(60, 0, 60, 160) offset:CGPointZero];
		
		// Animation using Sprite Sheet
		spBatterReady = [[CCSprite spriteWithSpriteFrame:frameReady0] retain];
		spBatterReady.position = ccp(BAT_START_X, BAT_START_Y);
		
		NSMutableArray *aniReadyFrames = [NSMutableArray array];
		[aniReadyFrames addObject:frameReady0];
		[aniReadyFrames addObject:frameReady1];
		
		CCAnimation *animationReady = [CCAnimation animationWithName:@"ready" delay:0.2f frames:aniReadyFrames];
		aniBatterReady = [[CCAnimate actionWithAnimation:animationReady restoreOriginalFrame:NO] retain];
		
		// 
		// batter swing
		//
		CCTexture2D *textureSwing = [[CCTextureCache sharedTextureCache] addImage:@"bat_swing.png"];
		
		// manually add frames to the frame cache
		CCSpriteFrame *frameSwing0 = [CCSpriteFrame frameWithTexture:textureSwing rect:CGRectMake(0, 0, 300, 160) offset:CGPointZero];
		CCSpriteFrame *frameSwing1 = [CCSpriteFrame frameWithTexture:textureSwing rect:CGRectMake(300, 0, 300, 160) offset:CGPointZero];
		CCSpriteFrame *frameSwing2 = [CCSpriteFrame frameWithTexture:textureSwing rect:CGRectMake(600, 0, 300, 160) offset:CGPointZero];
		
		// Animation using Sprite Sheet
		spBatterSwing = [[CCSprite spriteWithSpriteFrame:frameSwing0] retain];
		spBatterSwing.position = ccp(BAT_START_X, BAT_START_Y-30);
		
		NSMutableArray *aniSwingFrames = [NSMutableArray array];
		[aniSwingFrames addObject:frameSwing0];
		[aniSwingFrames addObject:frameSwing1];
		[aniSwingFrames addObject:frameSwing2];
		
		CCAnimation *animationSwing = [CCAnimation animationWithName:@"swing" delay:0.1f frames:aniSwingFrames];
		aniBatterSwing = [[CCAnimate actionWithAnimation:animationSwing restoreOriginalFrame:NO] retain];
	}	
	return self;
}

- (void) drawBatter
{
	
}

@end








